<?php

	header('Content-Type: text/xml');

	include_once('classes/functionDb.php');

	$MyKind = $_GET["kind_device"];
	$MyId  = $_GET["dev_id"];
	
	$MyQuery = 'SELECT * FROM ' . $MyKind . ' WHERE ' . $MyKind . '_ID=' .$MyId;
	$MyConnector  = ConnectUser();
	$MyResult = $MyConnector -> query($MyQuery);

	mysqli_close($MyConnector);
	
	$MyRow = $MyResult->fetch_row();
	
	switch($MyKind){
		case "disk":
			ShowDiskInfo($MyRow);
			break;
		case "graphic":
			ShowGraphicInfo($MyRow);
			break;
		case "memory":
			ShowMemoryInfo($MyRow);
			break;
		case "motherboard":
			ShowMotherboardInfo($MyRow);
			break;
		case "processor":
			ShowProcessorInfo($MyRow);
			break;
	}
	
	function ShowDiskInfo($pRow){
		$first  = $_GET["first"];
		$MyTable;
		if ($first == "1") {
			$MyTable = array(	"kategoria" => $pRow[1],
								"pojemnosc" => $pRow[2],
								"interfejs" => $pRow[3],
								"predkosc" => $pRow[4],
								"wymiary" => $pRow[5],
								"waga" => $pRow[6],
								"cache" => $pRow[7]
						 	);
		} else {
			$MyTable = array(	"kategorias" => $pRow[1],
								"pojemnoscs" => $pRow[2],
								"interfejss" => $pRow[3],
								"predkoscs" => $pRow[4],
								"wymiarys" => $pRow[5],
								"wagas" => $pRow[6],
								"caches" => $pRow[7]
						 	);
		}
		
		DisplayInfo($MyTable);
	}
	
	function ShowGraphicInfo($pRow){
		$first  = $_GET["first"];
		$MyTable;
		if ($first == "1") {
			$MyTable = array(	"producent" => $pRow[1],
								"chipset" => $pRow[2],
								"typ_chipset" => $pRow[3],
								"typ_zlacza" => $pRow[4],
								"ramdac" => $pRow[5],
								"rodzaj_pamieci" => $pRow[6],
								"czestotliwosc_pamieci" => $pRow[7],
								"taktowanie" => $pRow[8],
								"max_rozdzielczosc" => $pRow[9]
							);
		} else {
			$MyTable = array(	"producents" => $pRow[1],
								"chipsets" => $pRow[2],
								"typ_chipsets" => $pRow[3],
								"typ_zlaczas" => $pRow[4],
								"ramdacs" => $pRow[5],
								"rodzaj_pamiecis" => $pRow[6],
								"czestotliwosc_pamiecis" => $pRow[7],
								"taktowanies" => $pRow[8],
								"max_rozdzielczoscs" => $pRow[9]
							);
		}
		
		DisplayInfo($MyTable);
	}
	
	function ShowMemoryInfo($pRow){
		$first  = $_GET["first"];
		$MyTable;
		if ($first == "1") {
			$MyTable = array(	
								"rodzaj" => $pRow[1],
								"pojemnosc" => $pRow[2],
								"max_taktowanie" => $pRow[3],
								"napiecie" => $pRow[4],
								"ilosc_pin" => $pRow[5]
							);
		} else {
			$MyTable = array(	
								"rodzajs" => $pRow[1],
								"pojemnoscs" => $pRow[2],
								"max_taktowanies" => $pRow[3],
								"napiecies" => $pRow[4],
								"ilosc_pins" => $pRow[5]
							);
		}
		
		
		DisplayInfo($MyTable);
	}
	
	function ShowMotherboardInfo($pRow){
		$IsRaid = ($pRow[9] == 1) ? "Tak" : "Nie";
		$first  = $_GET["first"];
		$MyTable;
		if ($first == "1") {
			$MyTable = array(	"slot" => $pRow[1],
								"processor" => $pRow[2],
								"standard" => $pRow[3],
								"producent" => $pRow[4],
								"chipset" => $pRow[5],
								"rodzaj_pamieci" => $pRow[6],
								"max_wielkosc" => $pRow[7],
								"liczba_gniazd" => $pRow[8],
								"raid" => $IsRaid
							);
		} else {
			$MyTable = array(	"slots" => $pRow[1],
								"processors" => $pRow[2],
								"standards" => $pRow[3],
								"producents" => $pRow[4],
								"chipsets" => $pRow[5],
								"rodzaj_pamiecis" => $pRow[6],
								"max_wielkoscs" => $pRow[7],
								"liczba_gniazds" => $pRow[8],
								"raids" => $IsRaid
							);
		}
		
		DisplayInfo($MyTable);
	}
	
	function ShowProcessorInfo($pRow){
		$first  = $_GET["first"];
		$MyTable;
		if ($first == "1") {
			$MyTable = array(	
								"typ" => $pRow[1],
								"ilosc_rdzeni" => $pRow[2],
								"zlacze" => $pRow[3],
								"czestotliwosc" => $pRow[4],
								"technologia" => $pRow[5],
								"wydzielana_moc" => $pRow[6],
								"lone" => $pRow[7],
								"ltwo" => $pRow[8],
								"lthree" => $pRow[9]
							);			
		} else {
			$MyTable = array(	
								"typs" => $pRow[1],
								"ilosc_rdzenis" => $pRow[2],
								"zlaczes" => $pRow[3],
								"czestotliwoscs" => $pRow[4],
								"technologias" => $pRow[5],
								"wydzielana_mocs" => $pRow[6],
								"lones" => $pRow[7],
								"ltwos" => $pRow[8],
								"lthrees" => $pRow[9]
							);
		}
		DisplayInfo($MyTable);
	}
	
	function DisplayInfo($pTable){
		echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
		echo '<data>';
		
		foreach ($pTable as $MyText => $MyValue){
			echo '<' . $MyText . '>' . $MyValue . '</' . $MyText . '>';
		}
		
		echo '</data>';
		die();
	}

?>